package com.atguigu.juc.date108;

import org.openjdk.jol.info.ClassLayout;

/**
 * @Author: shenhao
 * @CreatTime: 2024/10/8 20:11
 * @Version: 1.0
 * java对象内存布局,分为
 * 对象头,Mark Word ,类型指针
 * 对象体,
 * 对齐字节(对齐填充) 将对象的大小填充到8的倍数大小的字节数 如果原本就是8的倍数大小,不需要对齐填充
 */
public class PrintObjectHeadDemo {
    public static void main(String[] args) {
        Object obj = new Object();// 总之,Java中new了一个Object对象,占用的内存大小为2*8 =16字节
        System.out.println(ClassLayout.parseInstance(obj).toPrintable());
        Fish fish = new Fish();
        System.out.println(ClassLayout.parseInstance(fish).toPrintable());
    }
}

class Fish{
    private int id;
    //private String fishName;
    //private boolean flag;
}
